package main

import (
	"fmt"
	"games.com/server/internal/activityservice"
	"games.com/server/internal/authservice"
	"games.com/server/internal/noticeservice"
	"games.com/server/internal/pkg/config"
	"games.com/server/internal/rewardservice"
	"games.com/server/internal/setup"
	"log"
	"net/http"
)

func main() {
	conf, err := setup.InitConfig()
	if err != nil {
		log.Fatalf("Error init conf, %s", err)
		return
	}

	_, err = authservice.NewAuthService(conf)
	if err != nil {
		log.Fatalf("failed to new authservice, %s", err)
		return
	}
	_, err = rewardservice.NewRewardService(conf)
	if err != nil {
		log.Fatalf("failed to new rewardservice, %s", err)
	}
	_, err = activityservice.NewActivityService(conf)
	if err != nil {
		log.Fatalf("failed to new activityservice, %s", err)
		return
	}
	_, err = noticeservice.NewNoticeService(conf)
	if err != nil {
		log.Fatalf("failed to new noticeservice, %s", err)
		return
	}

	run(conf)
}

func run(config *config.Config) {
	fmt.Printf("Server is running on %s\n", config.ListenAddr)
	log.Fatal(http.ListenAndServe(config.ListenAddr, nil))
}
